package flexjson.transformer;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class HibernateTransformer extends ObjectTransformer {

    protected Class resolveClass(Object obj) {
        return findBeanClass( obj );
    }

    public Class findBeanClass(Object object) {
        try {
            Method method = object.getClass().getMethod("getHibernateLazyInitializer", new Class[0]);
            Object initializer = method.invoke( object , new Object[0]);
            Method pmethod = initializer.getClass().getMethod("getPersistentClass", new Class[0]);
            return (Class)pmethod.invoke( initializer , new Object[0]);
        } catch (IllegalAccessException e) {
        } catch (NoSuchMethodException e) {
        } catch (InvocationTargetException e) {
        }
        return object.getClass();
    }

}
